package com.baizhiedu.baizhiappsys.service.impl;

import com.baizhiedu.baizhiappsys.dao.CourseDao;
import com.baizhiedu.baizhiappsys.dao.PayDao;
import com.baizhiedu.baizhiappsys.dto.ChartData;
import com.baizhiedu.baizhiappsys.entity.Course;
import com.baizhiedu.baizhiappsys.service.ChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lby
 */
@Service
public class ChartServiceImpl implements ChartService {
    @Autowired
    private PayDao payDao;
    @Autowired
    private CourseDao courseDao;

    @Override
    public Map getUserPieData() {
        Map map = new HashMap(2);
        String[] payMethods = {"支付宝","微信","Apple Pay","银联支付"};
        List<ChartData> chartDatas = new ArrayList<>();
        map.put("categories",payMethods);

        for (String payMethod:payMethods) {
            Integer integer = payDao.selectPayCountByPayMethod(payMethod);
            ChartData chartData = new ChartData(payMethod, integer);
            chartDatas.add(chartData);
        }

        map.put("chartData",chartDatas);
        return map;
    }
    /**
     * 设置热销课程 前五位 按照学习人数排名
     * courseNameList x轴
     * courseClickVolumeList 课程点击数
     * courseBuyVolumeList 课程购买数
     * @return
     */
    @Override
    public Map setCourseBar() {
        Map map = new HashMap(16);
//        获取数据
        List<Course> courses = courseDao.selectCourseOrderByCourseNumberStudents();
//        数据封装
        List<String> courseNameList = new ArrayList<>();
        List<Integer> courseClickVolumeList = new ArrayList<>();
        List<Integer> courseBuyVolumeList = new ArrayList<>();

        for (Course c:courses) {
            String courseName = c.getCourseName();
            courseNameList.add(courseName);
            Integer courseClickVolume = c.getCourseClickVolume();
            courseClickVolumeList.add(courseClickVolume);
            Integer courseNumberStudents = c.getCourseNumberStudents();
            courseBuyVolumeList.add(courseNumberStudents);
        }

        map.put("courseNameList",courseNameList);
        map.put("courseClickVolumeList",courseClickVolumeList);
        map.put("courseBuyVolumeList",courseBuyVolumeList);
        return map;
    }
}
